package com.foucus.myfouces.Adapter;

import android.app.Activity;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.foucus.myfouces.MVP.Model.SquareVideoResp;
import com.foucus.myfouces.R;
import com.foucus.myfouces.Resource.Util.GliderUtil;
import com.foucus.myfouces.Resource.Util.StartActivity;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by yf-06 on 2017/6/30.
 */

public class SquareVideoAdapter extends RecyclerView.Adapter<SquareVideoAdapter.ViewHolder> {

    private Context mContext;
    private List<SquareVideoResp.ResultBean.DataBean.VideoBean> squareVideoList;

    public SquareVideoAdapter(Context mContext, List<SquareVideoResp.ResultBean.DataBean.VideoBean> squareVideoList) {
        this.mContext = mContext;
        this.squareVideoList = squareVideoList;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_rcl_squae_video, parent, false);

        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        GliderUtil.bannerGlider(mContext, squareVideoList.get(position).getThumb(), holder.img_item_square_icon);
        holder.tv_item_square_name.setText(squareVideoList.get(position).getName());
        holder.img_item_square_icon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.e("ssss", "点击==》" + squareVideoList.get(position).getId());
                Log.e("ssss", "点击==》" + squareVideoList.get(position).getUrl());
                StartActivity.startVideoDetail((Activity) mContext, squareVideoList.get(position).getId());

            }
        });
    }

    @Override
    public int getItemCount() {
        return squareVideoList.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.img_item_square_icon)
        ImageView img_item_square_icon;
        @Bind(R.id.tv_item_square_name)
        TextView tv_item_square_name;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
